home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / utilities / file / sploin179.lha / vms.c < prev    next >
C/C++ Source or Header  |  1994-09-02  |  2KB  |  109 lines

  1. /* vms.c -- target dependent functions for VMS
  2.  * This is free software; you can redistribute it and/or modify it under the
  3.  * terms of the GNU General Public License, see the file COPYING.
  4.  *
  5.  * This file was written by Karl-Jose Filler <pla_jfi@pki-nbg.philips.de>
  6.  * and updated by Jean-loup Gailly.
  7.  *
  8.  * xmalloc changed for plain old malloc with error checking done in the actual code.
  9.  * Change made by Yves Perrenoud.
  10.  */
  11.  
  12. #include <stdio.h>
  13.  
  14. static char **vms_argv = NULL;
  15.  
  16. static int max_files = 10000;
  17.  
  18. struct    Str_desc {
  19.     int     length;
  20.     char    *addr;
  21. };
  22.  
  23. vms_expand_args(old_argc, argv)
  24.     int *old_argc;
  25.     char **argv[];
  26. {
  27.     int        i;
  28.     int        new_argc = 0;
  29.     int        context, status;
  30.     char    buf[255], *p;
  31.     
  32.     if (!(vms_argv = (char**)malloc((max_files+1)*sizeof(char*))))
  33.         error("Out of memory","");
  34.  
  35.     vms_argv[new_argc++] = **argv;
  36.  
  37.     for (i=1; i < *old_argc; i++) {
  38.     if (*argv[0][i] == '-') {   /* switches */
  39.         if (new_argc < max_files) {
  40.         vms_argv[new_argc++] = argv[0][i];
  41.         }
  42.     } else {            /* Files */
  43.         context = 0;
  44.         if (find_file_c(argv[0][i], buf, sizeof(buf), &context) & 1 != 1) {
  45.         /* 
  46.              * Wrong file ?
  47.          * forward it to gzip
  48.          */
  49.         if (new_argc < max_files) {
  50.             vms_argv[new_argc++] = argv[0][i];
  51.         }
  52.         } else {
  53.         if (!(p = (char*)malloc(strlen(buf)+1)))
  54.             error("Out of memory","");
  55.         strcpy(p, buf);
  56.         if (new_argc < max_files) {
  57.             vms_argv[new_argc++] = p;
  58.         }
  59.         while (find_file_c(argv[0][i], buf, 
  60.                sizeof(buf), &context) & 1 == 1) {
  61.             if (!(p = (char*)malloc(strlen(buf)+1)))
  62.                 error("Out of memory","");
  63.             strcpy(p, buf);
  64.             if (new_argc < max_files) {
  65.             vms_argv[new_argc++] = p;
  66.             }
  67.         }
  68.         }
  69.     }
  70.     }
  71.     if (new_argc <= max_files) {
  72.     *old_argc = new_argc;
  73.     vms_argv[new_argc] = NULL;
  74.     *argv = vms_argv;
  75.     } else {
  76.     free(vms_argv); /* the expanded file names should also be freed ... */
  77.     vms_argv = NULL;
  78.     max_files = new_argc + 1;
  79.     vms_expand_args(old_argc, argv);
  80.     }
  81. }
  82.  
  83. int find_file_c(in,out,out_len,context)
  84.     char *in;
  85.     char *out;
  86.     int   out_len;
  87.     int  *context;
  88. {
  89.     struct    Str_desc in_desc,out_desc;
  90.     int        status;
  91.     char    *p;
  92.   
  93.     in_desc.addr = in;
  94.     in_desc.length = strlen(in);
  95.   
  96.     out_desc.addr = out;
  97.     out_desc.length = out_len;
  98.   
  99.     status = lib$find_file(&in_desc,&out_desc,context);
  100.  
  101.     p   = out_desc.addr;
  102.     while(*p != ' ') {
  103.     p++;
  104.     }
  105.     *p = 0;
  106.   
  107.     return status;
  108. }
  109.